#include <allegro.h>
#include <stdio.h>

#define GFX_W 800
#define GFX_H 600
#define nb_images_bonus 3

typedef struct {
	BITMAP *img_bravo=NULL;
	BITMAP *img_erreur=NULL;
	BITMAP *img_perdu=NULL;
        BITMAP *img_kid=NULL;
       
	int x, y;
}Rebecca ;

//Module Background

BITMAP* load_background_bmp(char chemin_background[]);
void draw_background(BITMAP *Background,BITMAP*Buffer);
void destroy_background(BITMAP * Background);


//charger personnage:

void load_Rebecca(Rebecca *R);
void destroy_Rebecca(Rebecca *R);
void init_Rebecca(Rebecca *R);






int main() {

	char chemin_background[]="../images/background.bmp";

	BITMAP *Buffer;
	BITMAP *Background=NULL;
	
	Rebecca R;

	int compteur;

	/* General initialization function */
	allegro_init();
	if (install_keyboard() == -1) {
		allegro_message("Error! %s", allegro_error);
		return (-1);
	}
	set_color_depth(24);
	if (set_gfx_mode(GFX_AUTODETECT_WINDOWED, GFX_W, GFX_H, 0, 0) != 0) {
		set_gfx_mode(GFX_TEXT, 0, 0, 0, 0); /* here’s the command for text mode */
		allegro_message("Unable to initialize video mode!\n%s\n", allegro_error);
		return (1);
	}

	Buffer = create_bitmap(SCREEN_W, SCREEN_H);
	//loading images
	//loading Rebecca
	load_Rebecca(&R);
	


	//init position & direction
	compteur = 0;
	init_Rebecca(&R);

	while (!key[KEY_ESC]) {
		//vider le buffer
		clear_bitmap(Buffer);
		//drawing background
		draw_background(Background,Buffer);
		//drawing Rebecca
		draw_Rebecca(R,Buffer,compteur);
		//blit Buffer to screen
		blit(Buffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H);

		if (compteur == 10000)
			compteur = 0;
	}
	//destroy Rebecca
	destroy_Rebecca(&R);
	destroy_background(Background);
	destroy_bitmap(Buffer);
	return (0);
}
END_OF_MAIN();



/*
 * module background
 */

BITMAP* load_background_bmp(char chemin_background[])
{
	BITMAP* Background;

	Background=load_bitmap(chemin_background, NULL);
	if(Background == NULL){
		set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
		allegro_message("Unable to load image !\n%s\n", allegro_error);
		return (NULL);
	}
	return (Background);

}





void draw_background(BITMAP *Background,BITMAP*Buffer)
{
	blit(Background, Buffer, 0, 0, 0, 0, SCREEN_W, SCREEN_H);
}

void destroy_background(BITMAP * Background)
{
	destroy_bitmap(Background);
}


void load_Rebecca(Rebecca *R)
{
int i;
char tmp[60];
	R->img_bravo=load_bitmap("../images/bravo.bmp", NULL);
	R->img_erreur=load_bitmap("../images/erreur.bmp", NULL);
        R->img_perdu=load_bitmap("../images/perdu.bmp", NULL);
	
	for (i = 0; i <= nb_images_bonus; i++) 
	{
	sprintf(tmp, "../images/rep%d.bmp", i);
	R->bonus_exp[i]=load_bitmap(tmp, NULL);
	}

}

void init_Rebecca(Rebecca *R)
{
	
	R->x =500 ;
	R->y =400 ;
}



void destroy_Rebecca(Rebecca *R)
{
	int i;
		destroy_bitmap(R->img_bravo);
		destroy_bitmap(R->img_erreur);
                destroy_bitmap(R->img_perdu);

	for (i = 0; i <= nb_images_bonus; i++) {
		destroy_bitmap(R->bonus_exp[i]);
	}

}

// MODULE REBECCA BONUS //
void draw_Rebecca_bonus (Rebecca *R,BITMAP *Buffer, int indice)
{
	draw_sprite(Buffer, R->img_bonus_exp[indice],Rebecca->x, Rebecca->y);
}

//selon la reponse du jeu//
void affiche_Rebecca_bonus(Rebecca *R,int *rep ,BITMAP * Background)
{
if (rep==0) {
     draw_rebecca_bonus(R,Background,0);
}
else if (rep==1) {
     draw_rebecca_bonus(R,Background,1);
}
else if (rep==2) {
     draw_rebecca_bonus(R,Background,2);
}
}

// MODULE REBECCA STAGE selon int main du jeu//

void draw_rebecca_stage( Rebecca *R, BITMAP *Buffer, int *stage)
{
	if ((*stage)==3)
	{
	draw_sprite(Buffer, R->img_kid,500, 400);

}
// INCOMPLET selon pirate//
void depl_alea (Pirate *P, Rebecca *R, BITMAP *Background)
{
//R->x -=  (vitesse) ;

//P->x -= (vitesse) ;
}



